package com.heei.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @program: eureka-client
 * @description: Eureka-client 健康状态检测
 * @author: HuPing
 * @create: 2020-10-21 14:34
 **/
@Slf4j(topic = "DcController")
@RestController
public class DcController {

    @Autowired
    DiscoveryClient discoveryClient;

    @Value("${spring.profiles}")
    String profiles;

    @GetMapping("/dc")
    public String dc() {
        InetAddress address = null;//获取的是本地的IP地址
        log.info("进入 /dc");
        try {
            address = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            log.error("获取IP异常", e);
            return "异常";
        }
        String hostAddress = address.getHostAddress();
        return "Profile: " + profiles + " IP: " + hostAddress + " Services: " + discoveryClient.getServices();
    }
}
